<template>
  <div class="list-wrap">
    <a-form class="search-form" :form="form">
      <a-row :gutter="gutter">
        <a-col :lg="8" :xl="5" :xxl="4">
          <a-form-item label="审核状态">
            <a-input-group class="query-item" compact>
              <a-select style="width: 100%" v-model="verifyType">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">未审核</a-select-option>
                <a-select-option value="2">已审核</a-select-option>
                <a-select-option value="3">已拒绝</a-select-option>
              </a-select>
            </a-input-group>
          </a-form-item>
        </a-col>
        <a-col :lg="16" :xl="9" :xxl="7">
          <a-form-item label>
            <a-input-group class="query-item" compact>
              <a-select style="width: 40%" v-model="searchType">
                <a-select-option value="0">全部</a-select-option>
                <a-select-option value="1">省级分公司编号</a-select-option>
                <a-select-option value="2">省级分公司名称</a-select-option>
                <a-select-option value="3">省级分公司手机号</a-select-option>
                <a-select-option value="4">流水号</a-select-option>
                <!-- 搜索条件 0 全部 1 编号 2 名称 3 手机号 4 流水号 -->
              </a-select>
              <a-input style="width: 60%" v-model="keywords" placeholder="请输入查询条件"/>
            </a-input-group>
          </a-form-item>
        </a-col>
        <a-col :lg="12" :xl="10" :xxl="7">
          <a-form-item label="发起时间">
            <a-range-picker
              :placeholder="['开始时间', '结束时间']"
              @change="getCreateTime"
              v-model="createTime"
              class="select-range-time"
              style="width: 100%"
            />
          </a-form-item>
        </a-col>
        <a-col :lg="10" :xl="8" :xxl="6">
          <div class="top-btns">
            <a-button type="primary" @click="searchList">查询</a-button>
            <a-button type="primary" v-if="isBatchAudit">审核</a-button>
            <a-button @click="resetList">重置</a-button>
            <a-button type="primary" @click="exportPop"><a-icon type="download" />导出</a-button>
          </div>
        </a-col>
      </a-row>
    </a-form>
    <div class="search-result-list">
      <a-table
        :columns="columns"
        :dataSource="provinceCashData"
        rowKey="id"
        :loading="loading"
        :pagination="pagination"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :scroll="scrollX"
      >
        <span slot="action" slot-scope="text, item" class="action-wrap">
          <a @click="viewDetail(item)">查看详情</a>
          <a @click="hander(item, 1)">审核</a>
          <a @click="hander(item, 2)">拒绝</a>
        </span>
      </a-table>
      <span class="selected-item">{{`选中 ${selectedRowKeys.length} 条`}}</span>
      <pagination
        :total="total"
        @loadDataList="initPageList"
        ref="pageBand"
      />
    </div>
    <div class="modal-wrap">
      <remarks
        :title="auditTitle==1?'通过审核':'拒绝审核'"
        :isRefuse="auditTitle"
        :hint="`请确认是否${auditTitle==1?'通过审核':'拒绝审核'}?`"
        ref="remarks"
        @remarksConfirm="handleAuditOk"
      />
      <export-list ref="exportBand" exportApi="provinceWithdraw"/>
    </div>
  </div>
</template>
<script>
// 省分公司相关api引用
import { brwithdraw, updateBrwithdraw } from '../../store/provinceApi.js'
import { mixin } from '../../utils/remaksMixin'
export default {
  mixins: [mixin],
  data() {
    return {
      form: this.$form.createForm(this),
      gutter: {
        xs: 8,
        sm: 16,
        md: 16,
        lg: 24,
        xl: 24,
        xxl: 48
      },
      // 表格头标题
      columns: [
        {
          dataIndex: 'index',
          title: '序号',
          fixed: 'left',
          width: 60
        },
        {
          title: '省级分公司编号',
          dataIndex: 'branch_no'
        },
        {
          title: '省级分公司名称',
          dataIndex: 'branch_name'
        },
        {
          title: '省级分公司手机号',
          dataIndex: 'phone'
        },
        {
          title: '流水号',
          dataIndex: 'order_no'
        },
        {
          title: '提现金额(元)',
          dataIndex: 'amount'
        },
        {
          title: '手续费(元)',
          dataIndex: 'fee'
        },
        {
          title: '到账金额(元)',
          dataIndex: 'actual_amount'
        },
        {
          title: '持卡人姓名',
          dataIndex: 'card_user'
        },
        {
          title: '银行名称',
          dataIndex: 'bankname'
        },
        {
          title: '银行卡号',
          dataIndex: 'bankcard'
        },
        {
          title: '审核状态',
          dataIndex: 'status',
          customRender(status) {
            /* eslint-disable */
            if (status == 0) {
              return '未审核'
            } else if (status == 1) {
              return '已审核'
            } else if (status == 2) {
              return '已拒绝'
            }
            /* eslint-disable */
          }
        },
        {
          title: '发起时间',
          dataIndex: 'created_at'
        },
        {
          title: '处理时间',
          dataIndex: 'processed_at'
        },
        {
          title: '操作人',
          dataIndex: 'admin'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          width: 100,
          customRender: (text, row, index) => {
            return {
              children: (
                <div class="col-sql" title={text}>
                  {text}
                </div>
              ),
              attrs: {}
            }
          }
        },
        {
          title: '操作',
          fixed: 'right',
          width: 200,
          scopedSlots: { customRender: 'action' }
        }
      ],
      provinceCashData: [], // 表格列表
      auditTitle: '', // 弹窗头部标题
      loading: false, // 加载动画
      pagination: false, // 去掉表格自带的分页器
      scrollX: {}, // 表格数据过长时使用滚轮拖动-横向
      total: 0, // 总页数
      selectedRowKeys: [], // 已选中的表格行数
      // visible: false, // 弹窗默认隐藏
      start_time: 0, // 开始时间
      end_time: 0, // 结束时间
      createTime: [], // 选中的时间段默认为空
      isBatchAudit: false, // 批量审核按钮是否显示
      verifyType: '0', // 审核状态
      searchType: '0', // 查询筛选类型
      keywords: '', // 查询条件下的关键词
      maskClosable: false, // 点击遮罩层不让弹窗消失
      remarkTxt: '' // 弹窗的备注信息
    }
  },
  methods: {
    // 筛选加列表的显示
    initPageList(info) {
      this.loading = true
      brwithdraw({
        verifyType: this.verifyType, // 0 全部 1 未审核 2 已审核 3 已拒绝
        startTime: this.start_time,
        endTime: this.end_time,
        searchType: this.searchType, // 搜索条件 0 全部 1 编号 2 名称 3 手机号 4 流水号
        name: this.keywords,
        page: info.page,
        num: info.pageSize
      }).then(res => {
        var array = res.data.list
        for (let i = 0; i < array.length; i++) {
          array[i]['index'] = (info.page - 1) * info.pageSize + (i + 1)
        }
        this.provinceCashData = array
        this.loading = false
        // 有数据时字段过多就给滚轮拖动查看,无数据不显示滚轮
        if (res.data.list.length > 0) {
          this.scrollX = { x: 2500 }
        } else {
          this.scrollX = {}
        }
        // 总页数
        this.total = res.data.total_num
      })
    },
    // 筛选的查询按钮操作
    searchList() {
      this.$refs.pageBand.getData()
    },
    // 重置按钮操作
    resetList() {
      this.verifyType = '0'
      this.searchType = '0'
      this.keywords = ''
      this.createTime = [] // 让时间选择器表单内容置空
      this.start_time = 0
      this.end_time = 0
      this.$refs.pageBand.getData()
    },
    // 审核和拒绝
    hander(item, title) {
      if (Number(item.status) === 0) {
        this.editingItem = item
        // this.visible = true
        this.auditTitle = title
        this.openRemaks()
      } else {
        this.$message.warning('该记录已审核，无法重复操作！')
      }
    },
    // 审核弹窗的确认按钮
    handleAuditOk({ remarks }) {
      var data = {
        status: this.auditTitle,
        id: this.editingItem.uuid
      }
      if (remarks) {
        data.memo = remarks
      }
      updateBrwithdraw(data).then(e => {
        this.$message.success(e.data.message)
        // this.initPageList()
        this.$refs.pageBand.getEvent()
      })
    },
    // handleAuditOk() {
    //   var data = {
    //     status: this.auditTitle,
    //     id: this.editingItem.uuid
    //   }
    //   if (this.auditTitle !== 1 && this.remarkTxt == '') {
    //     this.$message.error('备注信息不能为空!')
    //     return false
    //   }
    //   if (!(this.remarkTxt == '')) {
    //     data.memo = this.remarkTxt
    //   }
    //   updateBrwithdraw(data)
    //     .then(e => {
    //       this.visible = !this.visible
    //       this.$message.success(e.data.message)
    //       this.initPageList()
    //     })
    // },
    // 拿到开始时间和结束时间的时间戳
    getCreateTime(date, str) {
      if (str[0] && str[1]) {
        this.start_time = new Date(str[0] + ' 00:00:00').getTime() / 1000
        this.end_time = new Date(str[1] + ' 23:59:59').getTime() / 1000
      } else {
        this.start_time = 0
        this.end_time = 0
      }
    },
    // 表格多选框操作
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
      if (selectedRowKeys && selectedRowKeys.length > 0) {
        this.isBatchAudit = true
      } else {
        this.isBatchAudit = false
      }
      console.log('已选:', selectedRowKeys)
    },
    exportPop () {
      this.$refs.exportBand.openPop()
    },
    // 详情页的跳转
    viewDetail(item) {
      this.$router.push({
        path: '/menu/province/cashWithdrawal/detail',
        query: { id: item.uuid }
      })
    }
  }
}
</script>
<style>
</style>
